home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 051-075 / scopedisk51 / cancel / cancel.asm < prev   
Assembly Source File  |  1995-03-18  |  10KB  |  410 lines

  1. ;Cancel! V1.0  Copyright 1987 Bryce Nesbitt.  Free, revokable license
  2. ;granted to use this code in any way provided all copyright notices remain
  3. ;intact and it is NOT used by or for or by any entity that has been commonly
  4. ;referred to as Robert W. Skyles, Skyles Electric Works, Jim Drew, Regie
  5. ;Warren or by any organization founded by, controlled, employing or
  6. ;profiting any such entity.  FISH use ok.  Send bugs (or bug reports :-),
  7. ;threats, suggestions or requests for permanent license to:
  8. ;       1712 Marin Ave.
  9. ;       Berkeley, Ca 94707-2902
  10. ;       bryce@cogsci.berkeley.EDU -or- ucbvax!cogsci!bryce
  11. ;
  12. ;USAGE
  13. ;       CLI - Cancel!       ;Disable *ALL* system requesters & alerts.
  14. ;           - Cancel! off       ;Enable requesters.
  15. ;       WB  - Brings up requester
  16. ;
  17. ;       Sometimes there is no human available to push "Cancel" on a
  18. ;       requester that might be generated.  Imagine a "disk full"
  19. ;       requester while running a unattended system!
  20. ;       This "Auto Human" sits dormant until it gets it's big chance
  21. ;       to press "Cancel" for you.
  22. ;
  23. ;BUGS
  24. ;       Cancel! refuses to install itself multiple times.  However, since
  25. ;       there is no such thing as a SetFunction() lock, OTHER tasks can
  26. ;       muddle things considerably.
  27. ;
  28. ;       This program features intellegent multitasking arbitration.  You,
  29. ;       the intellegent human, must not try to run two copies of this
  30. ;       program simultaneously.
  31. ;
  32. ;       "Software error, Task held" requesters may cause headaches.
  33. ;
  34. ;       Alerts really should be handled also.
  35. ;
  36. ;ADDITIONS
  37. ;       It would be useful in some cases to have a log of the text of
  38. ;       all the aborted requesters.  Perhaps allocate a `N' byte
  39. ;       file in a recoverable ram disk and record the latest `N' bytes
  40. ;       of requester messages.
  41. ;
  42. ;IMPLEMENTATION
  43. ;       Uses SetFunction to lobotomize AutoRequest() and BuildSysRequest(),
  44. ;
  45. ;NOTES
  46. ;       Should come to 812 bytes when assembled with Metacomco and Blink'ed
  47. ;       with the NODEBUG option set.
  48. ********************
  49.     NOLIST
  50.     INCLUDE 'exec/types.i'
  51. ;       INCLUDE 'exec/memory.i'
  52.     BITDEF  MEM,PUBLIC,0
  53.     BITDEF  MEM,CHIP,1
  54.     BITDEF  MEM,FAST,2
  55.     BITDEF  MEM,CLEAR,16
  56.     IFND    EXEC_ABLES_I
  57.     INCLUDE 'exec/ables.i'
  58.     ENDC
  59.     IFND    EXEC_DOSEXTENS_I
  60.     INCLUDE 'libraries/dosextens.i'
  61.     ENDC
  62. ;       INCLUDE 'intuition/intuitionbase.i'
  63. ib_ActiveWindow EQU $34
  64. ib_ActiveScreen EQU $38
  65. ib_FirstScreen  EQU $3C
  66.     LIST
  67.  STRUCTURE      SetFunctionLock,0
  68.         BYTE   sfl_Start    ;Must be set to $60. BRA.S in 68000
  69.         BYTE   sfl_Branch       ;Branch offset, value will vary
  70.         WORD   sfl_Magic_Cookie ;Must be $4AFC
  71.         APTR   sfl_OldVector    ;Function this lock displaced
  72.         APTR   sfl_Semaphore    ;Used to arbitrate this structure
  73.         WORD   sfl_MSize    ;Size to use with FreeMem()
  74.         WORD   sfl_Flags    ;See bit definitions...
  75.         BYTE   sfl_IDString     ;The actual string, *NOT* a pointer
  76.         ;No SIZEOF because it keeps going...
  77. jsrlib  MACRO
  78.     xref _LVO\1
  79.     jsr  _LVO\1(a6)
  80.     ENDM
  81. jmplib  MACRO
  82.     xref _LVO\1
  83.     jmp  _LVO\1(a6)
  84.     ENDM
  85. blink   MACRO
  86.     bchg.b #1,$bfe001
  87.     ENDM
  88. ********************
  89.         xref    _LVOAutoRequest
  90.         xref    _LVOBuildSysRequest
  91.  
  92. IBase       equr    d6
  93. DOSBase     equr    d5
  94. linelen     equr    d4
  95.  
  96.         CODE
  97. startup:    move.l  d0,linelen
  98.         move.l  4,a6
  99.         move.l  ThisTask(a6),a5
  100.         moveq   #0,d0       ;Set zero for later
  101.         move.l  pr_CLI(a5),d1   ;Pointer to CLI only structure
  102.         bne.s   fromCLI     ;If not zero, then flag zero...
  103.         lea.l   pr_MsgPort(a5),a0
  104.         jsrlib  WaitPort    ;Wait for Workbench's Message
  105. fromCLI     move.l  d0,-(a7)    ;Save message/flag for later...
  106. ******************* [A6=ExecBase][a5=this task]
  107.  
  108.         moveq   #20,d7
  109.         lea.l   DOSName(pc),a1
  110.         jsrlib  OldOpenLibrary  ;V1.0 Compatible :-)
  111.         move.l  d0,DOSBase
  112.         beq     e_dos
  113.         lea.l   IntuiName(pc),a1
  114.         jsrlib  OldOpenLibrary  ;V1.0 Compatible :-)
  115.         move.l  d0,IBase
  116.         beq     e_intui
  117.  
  118.         tst.l   (a7)        ;Test CLI flag on stack
  119.         beq.s   fromtheCLI
  120. ;---Do Workbench user interface---
  121.         FORBID
  122.         bsr     CHECKIF
  123.         move.l  d0,-(a7)    ;save flag
  124.         jsrlib  Permit
  125.         bsr     REMOVEIT    ;We wanna put up a requester
  126.         moveq   #0,d0
  127.         moveq   #0,d1
  128.         move.l  #320,d2
  129.         moveq   #68,d3
  130.         suba.l  a0,a0
  131.         suba.l  a2,a2
  132.         lea.l   ITextOk(pc),a3
  133.         tst.l   (a7)
  134.         bne.s   sayremove
  135.         lea.l   ITextId(pc),a1
  136.         bra.s   displayit
  137. sayremove       lea.l   ITextRemoved(pc),a1
  138. displayit       move.l  IBase,a6
  139.         jsrlib  AutoRequest
  140.         move.l  4,a6
  141.         move.l  (a7)+,d0
  142.         bne.s   RemoveIt
  143.         beq.s   DoItDude
  144.  
  145. ;---Do CLI UI---
  146. fromtheCLI:     subq.l  #1,linelen
  147.         beq.s   DoItDude
  148.  
  149. ;---Do the actual work---
  150. RemoveIt:       bsr     REMOVEIT
  151.         tst.l   (a7)        ;check CLI flag
  152.         bne.s   ExitOk
  153.         lea.l   Sremoved(pc),a0
  154.         moveq   #Eremoved-Sremoved,d3
  155.         bsr     WRITEIT
  156.         bra.s   ExitOk
  157.  
  158. DoItDude:       bsr     ADDIT
  159.         beq.s   e_nomem
  160.         tst.l   (a7)        ;check CLI flag
  161.         bne.s   ExitOk
  162.         lea.l   Sinstall(pc),a0
  163.         moveq   #Einstall-Sinstall,d3
  164.         bsr.s   WRITEIT
  165.         bne.s   ExitOk
  166.  
  167. ;--no memory, no fun--
  168. e_nomem     move.l  ThisTask(a6),a1
  169.         moveq   #ERROR_NO_FREE_STORE,d0
  170.         move.l  d0,pr_Result2(a1)
  171. ExitError       moveq   #20,d7      ;return code of "fail"
  172.         bra.s   Exit
  173.  
  174. ExitOk      moveq   #0,d7
  175. Exit        move.l  IBase,a1
  176.         jsrlib  CloseLibrary
  177. e_intui     move.l  DOSBase,a1
  178.         jsrlib  CloseLibrary
  179. e_dos
  180. ******************************* (a7)+=message d7=return code a6=exec
  181. ExitToDOS:      move.l  (a7)+,d2
  182.         beq.s   NotWB       ;If saved pointer is zero, exit to CLI...
  183.         FORBID
  184.         move.l  d2,a1       ;Return message to WB.  Use FORBID so
  185.         jsrlib  ReplyMsg    ;we won't be UnLoadSeg()'ed too early.
  186. NotWB       move.l  d7,d0       ;Set "failat" code
  187.         rts
  188. *******************
  189.  
  190. ;SYNOPSIS
  191. ;   error=WRITEIT(string,length),anything
  192. ;   z         a0     d3      a6
  193. ;
  194. ;GLOBALS
  195. ;   DOSBase
  196.  
  197. WRITEIT:    move.l  a6,-(a7)
  198.         move.l  DOSBase,a6
  199.         move.l  a0,d2
  200.         jsrlib  Output
  201.         move.l  d0,d1
  202.         move.l  d1,-(a7)
  203.         jsrlib  Write
  204.         lea.l   linefeed(pc),a0
  205.         move.l  (a7)+,d1
  206.         move.l  a0,d2
  207.         moveq   #1,d3
  208.         jsrlib  Write
  209.         move.l  (a7)+,a6
  210.         cmp.l   d0,d3
  211.         rts
  212.  
  213. ;SYNOPSIS
  214. ;   result=ADDIT(),exec
  215. ;   z
  216. ;
  217. ;FUNCTION
  218. ;   Add the functions, if they are not already added
  219. ;
  220. ;NOTES
  221. ;    Since the handler code is SHARED by any process that cares to call
  222. ;    the requester function, it must be copied to PUBLIC memory.  It must
  223. ;    also be re-entrant.
  224.  
  225. ADDIT       bsr     CHECKIF
  226.         beq     InPlace     ;Already there...
  227.         move.l  #HandlersEnd-HandlersStart,d0
  228.         move.l  #MEMF_PUBLIC+MEMF_CLEAR,d1
  229.         jsrlib  AllocMem
  230.         tst.l   d0          ;grumble.
  231.         bne.s   ok_mem
  232.         rts
  233.  
  234. ;---Copy to new location---
  235. ok_mem      ;[d0=memblock]
  236.         move.l  a2,-(a7)
  237.         move.l  d0,a1
  238.         lea.l   HandlersStart(pc),a0
  239.         moveq   #((HandlersEnd-HandlersStart)/4)-1,d1
  240. copylp      move.l  (a0)+,(a1)+     ;Copy handler to PUBLIC Memory
  241.         dbra    d1,copylp
  242.  
  243. ;---Try to add the newly prepared request ---
  244.         ;[d0=memblock]
  245.         move.l  d0,a2
  246.  
  247. ;--Add the new ones--
  248.         lea.l   NewAutoRequest-HS(a2),a0 ;our new function
  249.         move.l  a0,d0
  250.         move.w  #_LVOAutoRequest,a0     ;offset
  251.         move.l  IBase,a1        ;library
  252.         jsrlib  SetFunction
  253.         move.l  d0,NewAutoRequest+sfl_OldVector-HS(a2)
  254.  
  255.         lea.l   NewBuildSysRequest-HS(a2),a0 ;our new function
  256.         move.l  a0,d0
  257.         move.w  #_LVOBuildSysRequest,a0 ;offset
  258.         move.l  IBase,a1        ;library
  259.         jsrlib  SetFunction
  260.         move.l  d0,NewBuildSysRequest+sfl_OldVector-HS(a2)
  261.  
  262.         move.l  (a7)+,a2
  263. InPlace     moveq   #-1,d0
  264.         rts
  265.  
  266.  
  267. ;SYNOPSIS
  268. ;   result=REMOVEIT(),exec
  269. ;   z             a6
  270. ;
  271. ;FUNCTION
  272. ;   Remove the handlers if they are not already gone
  273.  
  274. REMOVEIT    FORBID
  275.         move.w  #_LVOBuildSysRequest,a0 ;offset
  276.         move.l  IBase,a1        ;library
  277.         bsr     ISIT
  278.         bne.s   notthere1
  279.         jsrlib  SetFunction
  280.  
  281. notthere1       move.w  #_LVOAutoRequest,a0     ;offset
  282.         move.l  IBase,a1        ;library
  283.         bsr     ISIT
  284.         bne.s   notthere2
  285.         move.l  d1,-(a7)
  286.         jsrlib  SetFunction
  287.  
  288. ;There is a finite chance that some code is still running in my
  289. ;SetFunction'ed code.  Oh, well.
  290.  
  291.         jsrlib  Permit
  292.         move.l  (a7)+,a1
  293.         move.l  #HandlersEnd-HandlersStart,d0
  294.         jmplib  FreeMem
  295. nothingtofree   rts
  296. notthere2       jmplib  Permit
  297.  
  298. ;SYNOPSIS
  299. ;   result,offset,library,OldVector,Vector=ISIT(offset,library),exec
  300. ;   z      a0     a1      d0        d1      a0     a1      a6
  301. ;
  302. ;FUNCTION
  303. ;   Check if we are already installed.  CALL WHILE FORBID'ed
  304. ;
  305. ;RESULT
  306. ;   Z=1 if found
  307. ;   d0=OldVector, if found.  zero otherwise.
  308. ;   d1=Vector, if found.  Garbage otherwise.
  309.  
  310. CHECKIF     move.w  #_LVOAutoRequest,a0     ;offset
  311.         move.l  IBase,a1        ;library
  312. ISIT        movem.l a0/a1/d2,-(a7)
  313.         move.l  2(a1,a0.w),a0
  314.         move.l  a0,d1       ;Get Vector
  315.         addq.l  #4,a0       ;Skip branch & cookie
  316.         move.l  (a0)+,d0    ;Get OldVector
  317.         addq.l  #8,a0       ;Skip Semaphore, etc.
  318.         lea.l   HandlersStart+16(pc),a1
  319.         moveq   #compareend-comparestart-1,d2
  320. namechk     cmpm.b  (a0)+,(a1)+
  321.         dbne    d2,namechk
  322.         beq.s   foundit
  323.         moveq   #0,d0
  324.         moveq   #-1,d1
  325. foundit     movem.l (a7)+,a0/a1/d2
  326.         rts
  327.  
  328. **************************** text area *************************************
  329.  
  330. ITextId:    dc.b 0,1,1,0         ;pens, drawmode and filler
  331.         dc.w 20,6            ;XY
  332.         dc.l 0           ;NULL for default font
  333.         dc.l Sid         ;pointer to text
  334.         dc.l ITextId2        ;next IntuitText structure
  335. ITextId2    dc.b 0,1,1,0
  336.         dc.w 20,17
  337.         dc.l 0
  338.         dc.l Sinstall
  339.         dc.l 0
  340.  
  341. ITextRemoved:   dc.b 0,1,1,0
  342.         dc.w 20,6
  343.         dc.l 0
  344.         dc.l Sid
  345.         dc.l ITextId3
  346. ITextId3    dc.b 0,1,1,0
  347.         dc.w 20,17
  348.         dc.l 0
  349.         dc.l Sremoved
  350.         dc.l 0
  351.  
  352. ITextOk:    dc.b 0,1,1,0
  353.         dc.w 6,3
  354.         dc.l 0
  355.         dc.l SOk
  356.         dc.l 0
  357.  
  358. Sid         dc.b 'Cancel!, ',$a9,'1987 Bryce Nesbitt',0
  359.            ;dc.b 'Cancel!, +1987 Bryce Nesbitt',0
  360. Sinstall    dc.b 'Requesters will be Canceled!',0
  361. Einstall
  362. Sremoved    dc.b 'Requesters are now enabled.',0
  363. Eremoved
  364. SOk         dc.b 'Ok',0
  365. IntuiName       dc.b 'intuition.library',0
  366. DOSName     dc.b 'dos.library',0
  367. linefeed    dc.b 10
  368.  
  369. ****************************** handlers ************************************
  370.  
  371. ;These are the parts that gets installed to do the actual 'dirty work'.
  372. ;The header provides a format for the name of this module, the pointer
  373. ;to the old function, and information on how to remove it.
  374.  
  375.         cnop    0,4
  376. HandlersStart:
  377. HS:
  378. NewAutoRequest: bra.s   TheCode1
  379.         dc.w    $4afc
  380.         dc.l    0
  381.         dc.l    0
  382.         dc.w    0
  383.         dc.w    1
  384. comparestart
  385.         dc.b    'Cancel!',0
  386.         cnop    0,2
  387. compareend
  388. NewBuildSysRequest: bra.s   TheCode1
  389.         dc.w    $4afc
  390.         dc.l    0
  391.         dc.l    0
  392.         dc.w    0
  393.         dc.w    1
  394.         dc.b    'Cancel!',0
  395.  
  396.         cnop   0,2
  397. TheCode1:       moveq   #0,d0       ;FALSE
  398.         rts
  399.  
  400.         cnop    0,4
  401. HandlersEnd:
  402. ********************
  403.         END
  404.  
  405. ----
  406.     Craig Norborg
  407.     comp.sources.amiga moderator
  408.  
  409.  
  410.